import { Controller } from 'egg';
import jwt from 'jsonwebtoken';
export default class UserController extends Controller {
  public async loginCallback() {
    const { ctx } = this;
    if (ctx.isAuthenticated()) {
      //如果用户登录成功了，就会把用户信息赋给ctx.user
      /* let data = {
        status: 'ok',
        type: ctx.user.type,
        currentAuthority: ctx.user.roles
      };
      var token = jwt.sign(data, 'secret');
      ctx.body = {
        success: true,
        data: token
      } */
      ctx.body = {
        status: 'ok',
        type: ctx.user.type,
        currentAuthority: ctx.user.roles
      }
    } else {
      ctx.body = {
        success: false,
        error: '用户登录失败'
      }
    }
  }

  public async addUser() {
    const { ctx } = this;
    ctx.body = {
      success: true,
      data: '添加用户成功'
    }
  }
}
